import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

// const root = ReactDOM.createRoot(document.getElementById('root'));
// root.render(
//   <React.StrictMode>
//     <App />
//   </React.StrictMode>
// );

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
let root
function render(props = {}) {
  let { container } = props
  root = ReactDOM.createRoot(
    container ? container.querySelector('#root') : document.getElementById('root')
  );
  root.render(
    <App />
  );
}
// 独立运行
if (!window.__POWERED_BY_QIANKUN__) {
  render({})
}
let _props
export async function bootstrap(props) {
  console.log(1);
}

export async function mount(props) {
  console.log(2);
  _props = props
  _props.setGlobalState({ name: 'jw', age: 1030 })
  // 如果没传props,会样式丢失掉!
  render(props)
}

export async function unmount(props) {
  let { container } = props
  // react17的!!! (已被弃用,但是依然可以从reactdom包里导入)
  // ReactDOM.unmountComponentAtNode(
  //   container ? container.querySelector('#root') : document.getElementById('root')
  // )
  // react18!!!
  root.unmount(
    container ? container.querySelector('#root') : document.getElementById('root')
  )
}
